<template>
  <div>
    <el-dialog
      title="提示"
      width="45%"
      :before-close="handleClose"
      :visible.sync="dialogVisible"
    >
      <el-form
        ref="form"
        :inline="true"
        :rules="rules"
        :model="form"
        label-width="80px"
      >
        <el-form-item label="姓名" prop="name">
          <el-input placeholder="请输入" v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="age">
          <el-input placeholder="请输入" v-model="form.age"></el-input>
        </el-form-item>
        <el-form-item label="年龄" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择活动区域">
            <el-option label="男" value="1"></el-option>
            <el-option label="女" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生日" prop="birth">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.birth"
            style="width: 100%"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="地址" prop="addr">
          <el-input
            placeholder="请输入"
            type="textarea"
            v-model="form.addr"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit"> 确 定 </el-button>
      </span>
    </el-dialog>

    <div class="">
      <el-button @click="dialogVisible = true">新增</el-button>
    </div>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="date" label="日期" width="180"> </el-table-column>
      <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
      <el-table-column prop="address" label="地址"> </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        name: "",
        age: "",
        sex: "",
        birth: "",
        addr: "",
      },
      rules: {
        name: [{ required: true, message: "请输入", trigger: "blur" }],
        age: [{ required: true, message: "请输入", trigger: "blur" }],
        sex: [{ required: true, message: "请输入", trigger: "blur" }],
        birth: [{ required: true, message: "请输入", trigger: "blur" }],
        addr: [{ required: true, message: "请输入", trigger: "blur" }],
      },
      tableData: [],
    };
  },
  methods: {
    // 确认保持提交
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          // 晴空表单的数据
          this.$refs.form.resetFields();
          // 关闭弹窗
          this.dialogVisible = false;
        }
      });
    },
    // 弹窗关闭时
    handleClose() {
      // 晴空表单的数据
      this.$refs.form.resetFields();
      // 关闭弹窗
      this.dialogVisible = false;
    },
    // 取消按钮
    cancel() {
      this.handleClose();
    },
  },
};
</script>

<style></style>
